package Gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;

import controller.LivingAreasControl;
import controller.MarketingTemplateControl;
import controller.ProductControl;

import Client_Server.ClientConsole;
import Entity.Template;
import javax.swing.JComboBox;


// TODO: Auto-generated Javadoc
/**
 * The Class MarketingTemplates.
 */
public class MarketingTemplates extends JPanel{
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -6400283674228776823L;
	
	/** The Template id label. */
	public static JLabel TemplateIDLabel;
	
	/** The Template product label. */
	public static JLabel TemplateProductLabel;
	
	/** The Template age label. */
	public static JLabel TemplateAgeLabel;
	
	/** The Template geograph label. */
	public static JLabel TemplateGeographLabel;
	
	/** The Template interesting label. */
	public static JLabel TemplateInterestingLabel;
	
	/** The Template importance label. */
	public static JLabel TemplateImportanceLabel;

	public static JLabel KitchenLabel;

	
	/** The Template permission label. */
	public static JLabel TemplatePermissionLabel;

	
	/** The Template message label. */
	public static JLabel TemplateMessageLabel;
	
	/** The Order label. */
	public static JLabel OrderLabel;
	
	/** The Order label2. */
	public static JLabel OrderLabel2;
	
	/** The Order label3. */
	public static JLabel OrderLabel3;
	
	/** The Template id text field. */
	public static JTextField TemplateIDTextField = null;
	
	/** The Template product text field. */
	public static JTextField TemplateProductTextField;
	
	/** The Template age text field. */
	public static JTextField TemplateAgeTextField = null;
	
	/** The Template geograph text field. */
	public static JTextField TemplateGeographTextField = null;


	
	/** The Template interesting text field. */
	public static JTextField TemplateInterestingTextField = null;
	
	/** The Template importance text field. */
	public static JTextField TemplateImportanceTextField = null;
	
	/** The Template permission text field. */
	public static JTextField TemplatePermissionTextField = null;

	/** The Template message text field. */
	public static JTextField TemplateMessageTextField = null;
	
	/** The Addbutton. */
	public static JButton Addbutton;
	
	/** The displaypidbutton. */
	public static JButton displaypidbutton;
	
	/** The displaypidbutton2. */
	public static JButton displaypidbutton2;
	
	/** The confirmation lable. */
	public static JLabel confirmationLable=null;
	
	/** The confirmation lable2. */
	public static JLabel confirmationLable2=null;
	
	/** The confirmation lable3. */
	public static JLabel confirmationLable3=null;
	
	/** The back button. */
	public static JButton backButton = new JButton("Back");
	
	/** The flag. */
	public String flag=null;
	
	/** The text area. */
	public static JTextArea textArea;
	
	/** The text area_1. */
	public static JTextArea textArea_1;
	
	/** The Etemplate. */
	private Template Etemplate;
	
	/** The Ctemplate. */
	private MarketingTemplateControl Ctemplate;
	
	/** The pc. */
	private ProductControl pc;
	
	/** The C living areas. */
	private LivingAreasControl CLivingAreas;
	
	/** The lbl click display button. */
	private JLabel lblClickDisplayButton;
	
	/** The displaypidbutton3. */
	private JButton displaypidbutton3;
	
	/** The text area_2. */
	public static JTextArea textArea_2;
	private JComboBox<String> Kitchen_comboBox;
	private JComboBox<String> Crockery_comboBox;
	private JComboBox<String> Picnic_comboBox;
	private JLabel CrockeryLabel;
	private JLabel PicnicLabel;
	private JLabel OrderLabel4;
	private JComboBox <String>Interest_comboBox;
	private JComboBox <String>Importance_comboBox;

;	
	
	/**
	 * Instantiates a new marketing templates.
	 */
	public MarketingTemplates()
	{
		super();
		viewDisplay();
	}

	/**
	 * View display.
	 */
	public void viewDisplay(){
		this.setSize( 1500,765 ); //set Frame size
		this.setLayout(null); //set layout
		OrderLabel = new JLabel();     //set new label
		OrderLabel.setBounds(new Rectangle(374, 70, 283, 19));//set label's  size and location
		OrderLabel.setText("Please insert template details:"); 
		OrderLabel.setFont(new Font("Arial", Font.ITALIC,16)); //set label font and size
		TemplateIDLabel = new JLabel();     //set new label
		TemplateIDLabel.setBounds(new Rectangle(450, 138, 113, 18));//set label's  size and location
		TemplateIDLabel.setText("Template Id:"); 
		TemplateIDLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateProductLabel = new JLabel();     //set new label
		TemplateProductLabel.setBounds(new Rectangle(450, 194, 113, 19));//set label's  size and location
		TemplateProductLabel.setText("Product ID:"); 
		TemplateProductLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateAgeLabel = new JLabel();     //set new label
		TemplateAgeLabel.setBounds(new Rectangle(450, 249, 113, 18));//set label's  size and location
		TemplateAgeLabel.setText("From age:");   
		TemplateAgeLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateGeographLabel = new JLabel();     //set new label
		TemplateGeographLabel.setBounds(new Rectangle(450, 297, 113, 18));//set label's  size and location
		TemplateGeographLabel.setText("Geographic area:");  
		TemplateGeographLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateInterestingLabel = new JLabel();     //set new label
		TemplateInterestingLabel.setBounds(new Rectangle(450, 343, 143, 18));//set label's  size and location
		TemplateInterestingLabel.setText("Customer's interesting:"); 
		TemplateInterestingLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateImportanceLabel = new JLabel();     //set new label
		TemplateImportanceLabel.setBounds(new Rectangle(450, 389, 143, 18));//set label's  size and location
		TemplateImportanceLabel.setText("Customer's importance:");   
		TemplateImportanceLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		KitchenLabel = new JLabel();     //set new label
		KitchenLabel.setBounds(new Rectangle(760, 150, 50, 18));//set label's  size and location
		KitchenLabel.setText("Kitchen:");   
		KitchenLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		TemplateMessageLabel = new JLabel();     //set new label
		TemplateMessageLabel.setBounds(new Rectangle(450, 439, 113, 18));//set label's  size and location
		TemplateMessageLabel.setText("Marketing Message:");   
		TemplateMessageLabel.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		OrderLabel2 = new JLabel();     //set new label
		OrderLabel2.setBounds(new Rectangle(10, 84, 283, 19));//set label's  size and location
		OrderLabel2.setText("Click Display button to view products in Database"); 
		OrderLabel2.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		OrderLabel3 = new JLabel();     //set new label
		OrderLabel3.setBounds(new Rectangle(991, 41, 283, 19));//set label's  size and location
		OrderLabel3.setText("Click Display button to view templated products:"); 
		OrderLabel3.setFont(new Font("Arial", Font.ITALIC,12)); //set label font and size
		this.add(TemplateIDLabel, null);   //add label to the panel
		this.add(TemplateProductLabel, null);   //add label to the panel
		this.add(TemplateAgeLabel, null);   //add label to the panel
		this.add(TemplateGeographLabel, null);   //add label to the panel
		this.add(TemplateInterestingLabel, null);   //add label to the panel
		this.add(TemplateImportanceLabel, null);   //add label to the panel
		this.add(KitchenLabel, null);   //add label to the panel
		this.add(TemplateMessageLabel, null);   //add label to the panel
		this.add(OrderLabel, null);   //add label to the panel
		this.add(OrderLabel2, null);   //add label to the panel
		this.add(OrderLabel3, null);   //add label to the panel
		backButton.setBounds(664, 500, 150, 23);   //set button's size and location
		add(backButton);          // add button to the panel
		this.flag="pid";
		TemplateIDTextField = new JTextField(); 
		TemplateIDTextField.setBounds(new Rectangle(590, 139, 127, 17)); //set field's  size and location
		this.add(TemplateIDTextField, null);   // add the field to the panel
		
		TemplateProductTextField = new JTextField(); 
		TemplateProductTextField.setBounds(new Rectangle(590, 195, 127, 17)); //set field's  size and location
		this.add(TemplateProductTextField, null);   // add the field to the panel
		
		TemplateAgeTextField = new JTextField();
		TemplateAgeTextField.setBounds(new Rectangle(590, 250, 127, 17)); //set field's  size and location
		this.add(TemplateAgeTextField, null);   // add the field to the panel
		
		TemplateGeographTextField = new JTextField();
		TemplateGeographTextField.setBounds(new Rectangle(590, 298, 127, 17)); //set field's  size and location
		this.add(TemplateGeographTextField, null);
		
		TemplateMessageTextField = new JTextField(); 
		TemplateMessageTextField.setBounds(592, 440, 350, 17);//set field's size and location
		this.add(TemplateMessageTextField,null); // add the field to the panel
		
		Interest_comboBox = new JComboBox<String>();
		Interest_comboBox.setBounds(603, 343, 76, 20);
		Interest_comboBox.addItem("");
		Interest_comboBox.addItem("1");
		Interest_comboBox.addItem("2");
		Interest_comboBox.addItem("3");
		Interest_comboBox.addItem("4");
		Interest_comboBox.addItem("5");
		Interest_comboBox.addItem("6");
		Interest_comboBox.addItem("7");
		Interest_comboBox.addItem("8");
		Interest_comboBox.addItem("9");
		Interest_comboBox.addItem("10");
		add(Interest_comboBox);
		
		Importance_comboBox = new JComboBox<String>();
		Importance_comboBox.setBounds(603, 389, 76, 20);
		Importance_comboBox.addItem("");
		Importance_comboBox.addItem("1");
		Importance_comboBox.addItem("2");
		Importance_comboBox.addItem("3");
		Importance_comboBox.addItem("4");
		Importance_comboBox.addItem("5");
		Importance_comboBox.addItem("6");
		Importance_comboBox.addItem("7");
		Importance_comboBox.addItem("8");
		Importance_comboBox.addItem("9");
		Importance_comboBox.addItem("10");
		add(Importance_comboBox);
	
		
		Kitchen_comboBox = new JComboBox<String>();
		Kitchen_comboBox.setBounds(845, 150, 127, 20);
		Kitchen_comboBox.addItem("");
		Kitchen_comboBox.addItem("Yes");
		Kitchen_comboBox.addItem("No");
		Kitchen_comboBox.getSelectedItem();
		add(Kitchen_comboBox);
		
		Crockery_comboBox = new JComboBox<String>();
		Crockery_comboBox.setBounds(845, 213, 127, 20);
		Crockery_comboBox.addItem("");
		Crockery_comboBox.addItem("Yes");
		Crockery_comboBox.addItem("No");
		add(Crockery_comboBox);
		
		Picnic_comboBox = new JComboBox<String>();
		Picnic_comboBox.setBounds(848, 280, 124, 20);
		Picnic_comboBox.addItem("");
		Picnic_comboBox.addItem("Yes");
		Picnic_comboBox.addItem("No");
		add(Picnic_comboBox);
		
		CrockeryLabel = new JLabel();
		CrockeryLabel.setText("Crockery:");
		CrockeryLabel.setFont(new Font("Arial", Font.ITALIC, 12));
		CrockeryLabel.setBounds(new Rectangle(450, 350, 143, 18));
		CrockeryLabel.setBounds(760, 213, 69, 18);
		add(CrockeryLabel);
		
		PicnicLabel = new JLabel();
		PicnicLabel.setText("Picnic:");
		PicnicLabel.setFont(new Font("Arial", Font.ITALIC, 12));
		PicnicLabel.setBounds(new Rectangle(450, 350, 143, 18));
		PicnicLabel.setBounds(768, 280, 42, 18);
		add(PicnicLabel);
		
		OrderLabel4 = new JLabel();
		OrderLabel4.setText("Give Permissions for each sector:");
		OrderLabel4.setFont(new Font("Arial", Font.ITALIC, 12));
		OrderLabel4.setBounds(new Rectangle(437, 310, 143, 18));
		OrderLabel4.setBounds(763, 100, 209, 18);
		add(OrderLabel4);
		
		 Addbutton = new JButton("Add template");              
			Addbutton.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					Etemplate=new Template();
					Etemplate.setTemplateId(TemplateIDTextField.getText());
					Etemplate.setProductId(TemplateProductTextField.getText());
					Etemplate.setAge(TemplateAgeTextField.getText());
					Etemplate.setGeographArea(TemplateGeographTextField.getText());
					Etemplate.setCusInterest((String)(Interest_comboBox.getSelectedItem()));
					Etemplate.setCusImportance((String)(Importance_comboBox.getSelectedItem()));
					Etemplate.setPermKitchen((String)(Kitchen_comboBox.getSelectedItem()));
					Etemplate.setPermCrockery((String)(Crockery_comboBox.getSelectedItem()));
					Etemplate.setPermPicnic((String)(Picnic_comboBox.getSelectedItem()));
					Etemplate.setTemlateMessage(TemplateMessageTextField.getText());
					Ctemplate=new MarketingTemplateControl();
					if(Ctemplate.CheckDetails(Etemplate.getTemplateId(),Etemplate.getProductId(),Etemplate.getAge(),Etemplate.getGeographArea(),Etemplate.getCusInterest(),Etemplate.getCusImportance(),Etemplate.getTemlateMessage(),Etemplate.getPermKitchen(),Etemplate.getPermCrockery(),Etemplate.getPermPicnic()))
					{
						Ctemplate.submitTemplate(Etemplate.getTemplateId(),Etemplate.getProductId(),Etemplate.getAge(),Etemplate.getGeographArea(),Etemplate.getCusInterest(),Etemplate.getCusImportance(),Etemplate.getTemlateMessage(),Etemplate.getPermKitchen(),Etemplate.getPermCrockery(),Etemplate.getPermPicnic());
						confirmationLable.setVisible(true);
					}
					 else{ 
						 confirmationLable.setVisible(true);
						 confirmationLable.setText("Please fill all the fields!!");
					 }
					 
				}
			});
			
			Addbutton.setBounds(483, 500, 150, 23);      //set button size
			add(Addbutton);                            //add button to the panel
			displaypidbutton = new JButton("Display");              
			displaypidbutton.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					pc=new ProductControl();
					pc.ShowProducts2();

				}
			});
			
			displaypidbutton.setBounds(60, 120, 150, 23);      //set button size
			add(displaypidbutton);
			
			displaypidbutton2 = new JButton("Display");            
			displaypidbutton2.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					pc=new ProductControl();
					pc.ShowTemplateProducts();

				}
			});
			
			displaypidbutton2.setBounds(1066, 83, 150, 23);      //set button size
			add(displaypidbutton2);
			
			displaypidbutton3 = new JButton("Display");
			displaypidbutton3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					CLivingAreas=new LivingAreasControl();
					CLivingAreas.ShowLivingAreas2();
					
				}
			});
			displaypidbutton3.setBounds(1066, 420, 150, 23);
			add(displaypidbutton3);
			
			
			confirmationLable = new JLabel("");           // set result label
			confirmationLable.setBounds(493, 534, 350, 150);  // set label's size and location
			add(confirmationLable);                        // add label to the panel
			confirmationLable.setVisible(false); 
			
			textArea = new JTextArea();
			textArea.setBackground(Color.LIGHT_GRAY);
			textArea.setEditable(false);
			textArea.setBounds(1076, 117, 162, 253);
			add(textArea);
			
			textArea_1 = new JTextArea();
			textArea_1.setBackground(Color.LIGHT_GRAY);
			textArea_1.setEditable(false);
			textArea_1.setBounds(47, 154, 203, 253);
			add(textArea_1);
			
			lblClickDisplayButton = new JLabel();
			lblClickDisplayButton.setText("Click Display button to view possible living areas:");
			lblClickDisplayButton.setFont(new Font("Arial", Font.ITALIC, 12));
			lblClickDisplayButton.setBounds(new Rectangle(991, 41, 283, 19));
			lblClickDisplayButton.setBounds(976, 395, 298, 19);
			add(lblClickDisplayButton);
			
			
			
			textArea_2 = new JTextArea();
			textArea_2.setEditable(false);
			textArea_2.setBackground(Color.LIGHT_GRAY);
			textArea_2.setBounds(1076, 460, 162, 253);
			add(textArea_2);
			

			
		}



	}
